
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        //数组长度2
        int n = scan.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = scan.nextInt();
        }
        int m = scan.nextInt();
        //统计频率
        int[] diff = new int[n+1];
        //获得查询
        for (int i = 0;i < m;i++) {
            int l = scan.nextInt() - 1;
            int r = scan.nextInt() - 1;
            diff[l]++;
            diff[r+1]--;
        }
        //差分合并
        for (int i = 1; i < diff.length; i++) {
            diff[i] += diff[i-1];
        }
        //原来的和
        long bSum = 0;
        for (int i = 0; i < n; i++) {
            bSum += arr[i]*diff[i];
        }
        Arrays.sort(diff, 0, n);
        Arrays.sort(arr, 0, n);
        //之后的和
        long aSum = 0;
        for (int i = 0; i < n; i++) {
            aSum += arr[i]*diff[i];
        }
        System.out.println(aSum-bSum);
        scan.close();
    }
    public static void main3(String[] args) {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
        //部落数
        int n = scan.nextInt();
        PriorityQueue<Integer> p = new PriorityQueue<>();
        for (int i = 0; i < n; i++) {
            p.add(scan.nextInt());
        }
        int priceSum = 0;
        while (p.size()>1) {
            int p1 = p.poll();
            int p2 = p.poll();
            int sum = p1 + p2;
            priceSum += sum*2;
            p.add(sum);
        }

        scan.close();
    }
    /**
     *
     * @param arr
     * @param n 表示次数
     * @return
     */
    public static int[] prefixSum(int[] arr, int n) {
        int[] nArr = new int[arr.length+1];
        for (int i = 1; i < arr.length; i++) {
            nArr[i] = nArr[i-1] + (int)Math.pow(arr[i-1], n);
            nArr[i] %= (long)1e9+7;
        }
        return nArr;
    }
    public static void main2(String[] args) {
        Scanner scanner = new Scanner(System.in);
        //n表示数组长度
        int n = scanner.nextInt();
        int[] arr = new int[n];
        int[] a = new int[n];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = scanner.nextInt();
            a[i] = arr[i];
        }
        //arr进行排序   , a数组保存原来的数据
        Arrays.sort(arr);
        HashSet<Integer> set = new HashSet<>();
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < a.length; i++) {
            set.add(arr[i]);
            map.put(arr[i], set.size());
        }
        for (int i = 0; i < a.length; i++) {
            System.out.print(map.get(a[i])+" ");
        }

    }
    public static void main01(String[] args) {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
        //长度
        int l = scan.nextInt();
        //查询次数
        int count = scan.nextInt();
        int[] arr = new int[l];
        for (int i = 0; i < l; i++) {
            arr[i] = scan.nextInt();
        }
        Arrays.sort(arr);
        int[][] arrs = new int[5][];
        for (int i = 0; i < arrs.length; i++) {
            for(int j = 1; j <= 5; j++) {
                arrs[i] = prefixSum(arr, j);
            }
        }

        long e = (long)1e9 + 7;
        while (count>=0) {
            //处理一次查询

            int r = scan.nextInt();
            //次方
            int p = scan.nextInt();
            long ans = arrs[p-1][r+1]%e + arrs[p-1][l];
            count--;
        }

        scan.close();
    }
}